import type {
  ActionConfig,
  DataRecord,
  FormConfig,
  PageConfig,
  PaginationConfig,
  SearchFieldConfig,
  TableColumn,
} from './config.type'

/**
 * 完整的页面配置
 */
const config = {
  // 页面基本信息
  page: {
    title: '菜单管理',
    description: '管理系统的菜单与按钮权限（树形）',
    permission: 'acl:permission',
    targetNameField: 'name',
  } as PageConfig,

  // API接口配置
  api: {
    GET_URL: '/permission',
    CREATE_URL: '/permission',
    UPDATE_URL: '/permission',
    DELETE_URL: '/permission',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'roleName',
        label: '角色名称',
        type: 'input',
        placeholder: '按角色名称搜索',
        clearable: true,
      },
    ] as SearchFieldConfig[],
    showReset: true,
    searchButtonText: '搜索',
    resetButtonText: '重置',
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 55,
      align: 'center',
    },
    {
      prop: 'name',
      label: '名称',
      minWidth: 'auto',
      align: 'left',
      sortable: true,
      showOverflowTooltip: true,
    },
    {
      prop: 'code',
      label: '编码',
      minWidth: 'auto',
      align: 'left',
      showOverflowTooltip: true,
    },
    {
      prop: 'type',
      label: '类型',
      width: 'auto',
      align: 'center',
      type: 'tag',
      tagConfig: {
        textMap: { 1: '菜单', 2: '按钮', 0: '全部' },
        typeMap: { 1: 'primary', 2: 'success', 0: 'info' },
      },
    },
    {
      prop: 'level',
      label: '层级',
      width: 'auto',
      align: 'center',
      sortable: true,
    },

    //  操作列在page.vue中统一配置
  ] as TableColumn<DataRecord>[],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'name',
        label: '名称',
        type: 'input',
        placeholder: '请输入名称',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'code',
        label: '编码',
        type: 'input',
        placeholder: '如 btn.User.add 或 Acl',
      },
      {
        prop: 'type',
        label: '类型',
        type: 'radio',
        required: true,
        options: [
          { label: '菜单', value: 1 },
          { label: '按钮', value: 2 },
        ],
      },
    ],
    rules: {
      name: [
        { required: true, message: '请输入名称', trigger: 'blur' },
        { min: 1, max: 50, message: '长度在 1 到 50 个字符', trigger: 'blur' },
      ],
      type: [{ required: true, message: '请选择类型', trigger: 'change' }],
    },
    labelWidth: '100px',
    dialogWidth: '640px',
    addTitle: '新增权限',
    editTitle: '编辑权限',
  } as FormConfig,

  // 操作按钮配置
  actions: {
    add: {
      text: '新增权限',
      icon: 'Plus',
      permission: 'btn.Permission.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.Permission.remove',
    },
  } as ActionConfig,

  // 分页配置
  pagination: {
    pageSizes: [10, 20, 50, 100],
    defaultPageSize: 10,
  } as PaginationConfig,

  // 消息配置
  messages: {
    loadSuccess: '菜单权限获取成功',
    loadError: '菜单权限获取失败',
    addSuccess: '权限添加成功！',
    addError: '权限添加失败',
    editSuccess: '权限修改成功！',
    editError: '权限修改失败',
    deleteSuccess: '删除成功',
    deleteError: '删除失败',
    batchDeleteSuccess: '批量删除成功',
    batchDeleteError: '批量删除失败',
    selectDeleteItems: '请选择要删除的数据',
    deleteConfirm: '确定要删除该权限吗？删除后无法恢复！',
    batchDeleteConfirm: '确定要删除选中的 {count} 个权限吗？删除后无法恢复！',
  },
}

export default config
